package homework;
import java.util.List;
import java.util.ArrayList;
import java.util.*;

/**
 *List
 *  @胡承伦
 */
public class ListMethod {
    List<Book> list1 = new ArrayList<Book>();

    public void find(int b) {
        for (int i = 0; i < list1.size(); i++) {
            if (b == (list1.get(i).getMember())) {
                System.out.println(list1.get(i).toString());
                return;
            }
        }
        System.out.println("你要找的图书不存在");
    }

    public void add(Book book) {
        list1.add(book);
    }

    public void delete(Book book) {
        list1.remove(book);
    }

    public void delete(int m) {
        for (int i = 0; i < list1.size(); i++) {
            if (m == (list1.get(i).getMember())) {
                list1.remove(list1.get(i));
            }
        }
    }

    public static void main(String[] args) {
        ListMethod list = new ListMethod();
        //添加图书信息；
        list.add(new Book(1, "堂吉诃德", 39.5, "文学出版社"));
        list.add(new Book(2, "草房子", 49.5, "文学出版社"));
        list.add(new Book(3, "善良", 59.5, "文学出版社"));
        list.add(new Book(4, "最美文", 10, "文学出版社"));
        for (int i = 0; i < list.list1.size(); i++) {
            System.out.println(list.list1.get(i).toString());
        }
        System.out.println("#############");
        //删除图书信息；
        list.delete(1);
        for (int i = 0; i < list.list1.size(); i++) {
            System.out.println(list.list1.get(i).toString());
        }
        System.out.println("############");
        //寻找图书；
        list.find(5);
        System.out.println("############");
        list.find(3);

    }
}
class Book {
    private int member;
    private String name;
    private double price;
    private String publish;

    public Book(int member, String name, double price, String publish) {
        this.member = member;
        this.name = name;
        this.price = price;
        this.publish = publish;
    }

    @Override
    public String toString() {
        return "Book{" +
                "member=" + member +
                ", name='" + name + '\'' +
                ", price=" + price +
                ", publish='" + publish + '\'' +
                '}';
    }
    public int getMember() {
        return member;
    }

    public String getName() {
        return name;
    }

    public double getPrice() {
        return price;
    }

    public String getPublish() {
        return publish;
    }
}